package com.fortune.service.impl;

import com.fortune.dao.MDRelationDao;
import com.fortune.dao.PMAccountMgtDao;
import com.fortune.dto.in.dealerRemind.DealerRemindConFirmDto;
import com.fortune.dto.in.dealerRemind.DealerRemindListDto;
import com.fortune.dto.in.mDAccountMgt.MDAccountListDto;
import com.fortune.entity.SimpleManufactory;
import com.fortune.service.MDRelationService;
import com.fortune.vo.dealerRemind.DealerRemindList;
import com.fortune.vo.mDAccountMgt.MDealerInfo;
import com.fortune.vo.mDAccountMgt.MDealerList;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.List;

@Service
public class MDRelationServiceImpl implements MDRelationService {
    @Autowired
    private MDRelationDao mdRelationDao;

    @Autowired
    private PMAccountMgtDao pmAccountMgtDao;

    /**
     * 查询经销商列表
     * @param companyId
     * @param mdAccountListDto
     * @return
     */
    @Override
    public List<MDealerList> queryDelareList(String companyId, MDAccountListDto mdAccountListDto) {
        return mdRelationDao.queryDelareList(companyId,mdAccountListDto);
    }

    /**
     * 查询经销商列表个数
     * @param companyId
     * @param mdAccountListDto
     * @return
     */
    @Override
    public int queryDelareListCount(String companyId, MDAccountListDto mdAccountListDto) {
        return mdRelationDao.queryDelareListCount(companyId,mdAccountListDto);
    }

    /**
     * 查询详情
     * @param phone
     * @return
     */
    @Override
    public MDealerInfo queryDealerInfo(String phone) {
        return mdRelationDao.queryMDealerInfo(phone);
    }

    /**
     * 经销商厂商关系表数据是否存在
     * @param companyId
     * @param id
     * @return
     */
    @Override
    public int queryRelationIsExist(String companyId, String id) {
        return mdRelationDao.queryRelationIsExist(companyId,id);
    }

    /**
     * 添加经销商
     * @param companyId
     * @param id
     * @return
     */
    @Override
    public int addRelationIs(String companyId, String id) {
        return mdRelationDao.addRelationIs(companyId,id);
    }

    /**
     * 删除经销商
     * @param companyId
     * @param id
     * @return
     */
    @Override
    public int delete(String companyId, String id) {
        return mdRelationDao.delete(companyId,id);
    }

	@Override
	public List<SimpleManufactory> listRelationedManufactories(String dId) {
		return mdRelationDao.listRelationedManufactories(dId);
	}

    /**
     * 经销商查询厂商添加提醒
     * @param dealerId
     * @param dealerRemindListDto
     * @return
     */
    @Override
    public List<DealerRemindList> queryCompanyByDealerList(String dealerId, DealerRemindListDto dealerRemindListDto) {
        return mdRelationDao.queryCompanyByDealerList(dealerId,dealerRemindListDto);
    }

    /**
     * 经销商查询厂商添加提醒个数
     * @param dealerId
     * @param dealerRemindListDto
     * @return
     */
    @Override
    public int queryCompanyByDealerListCount(String dealerId, DealerRemindListDto dealerRemindListDto) {
        return mdRelationDao.queryCompanyByDealerListCount(dealerId,dealerRemindListDto);
    }

    /**
     * 修改状态
     * @param dealerId
     * @param dealerRemindConFirmDto
     * @return
     */
    @Override
    public int updateConfirmType(String dealerId, DealerRemindConFirmDto dealerRemindConFirmDto) {
        String type = mdRelationDao.queryRelationType(dealerId,dealerRemindConFirmDto.getId());
        int num = 0;
        if (type.equals(String.valueOf(dealerRemindConFirmDto.getType())) && type.equals("YES")){
            return -2;
        }else if(type.equals(String.valueOf(dealerRemindConFirmDto.getType())) && type.equals("NO")){
            return -3;
        }else {
            num = mdRelationDao.updateType(dealerId,dealerRemindConFirmDto);
        }

        return num;
    }

    /**
     * 查询厂商下经销商最大数量
     * @param companyId
     * @return
     */
    @Override
    public int queryCompanyDealerMaxCount(String companyId) {
        return pmAccountMgtDao.queryCompanyDealerMaxCount(companyId);
    }

    /**
     * 查询厂商下经销商数量
     * @param companyId
     * @return
     */
    @Override
    public int queryDelareOfCompanyCount(String companyId) {
        return mdRelationDao.queryDelareOfCompanyCount(companyId);
    }

}
